package com.reform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reform.pojo.expert.ExpertScore;
import com.reform.mapper.ExpertScoreMapper;
import com.reform.res.Result;
import com.reform.res.ResultCode;
import com.reform.service.IExpertScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mortale
 * @since 2021-08-25
 */
@Service
public class ExpertScoreServiceImpl extends ServiceImpl<ExpertScoreMapper, ExpertScore> implements IExpertScoreService {

    @Autowired
    ExpertScoreMapper expertScoreMapper;

    @Override
    public Result creatExpertScore(ExpertScore expertScore) {
        if (expertScoreMapper.insert(expertScore) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.failure(ResultCode.FAILURE);
    }

    @Override
    public Result deleteExpertScore(ExpertScore expertScore) {
        if (expertScoreMapper.deleteById(expertScore) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.failure(ResultCode.FAILURE);
    }

    @Override
    public Result updateExpertScore(ExpertScore expertScore) {
        if (expertScoreMapper.updateById(expertScore) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.failure(ResultCode.FAILURE);
    }

    @Override
    public Result getExpertScores() {
        return Result.success(ResultCode.SUCCESS, expertScoreMapper.selectList(null));
    }

    @Override
    public Result getExpertScoreByProId(String proId) {
        return Result.success(ResultCode.SUCCESS, expertScoreMapper.selectList(new QueryWrapper<ExpertScore>().eq("pro_id", proId)));
    }
}
